package TUILayer;
import java.util.Scanner;
import ControlLayer.*;

/**
 * 
 * User interface - main menu
 * The entry-point for the application:
 * Create an instance of class MainMenuUI and the constructor starts the application
 * 
 * @author (group1) 
 * @version (2013.11.04)
 */
public class MainMenuUI extends InputOutput
{
    public AddressBookUI adrUI;   //references to other UI objects
    public DvdUI dvdUI;
    public LoanUI loanUI;

    public MainMenuUI() { mainMenuStart();  }
    
    public static void main(String[] args)
    {
        new MainMenuUI();
    }
    

    public void mainMenuStart()
    {
        boolean exit=false;
        while(!exit)
        {
            int choice = writeMainMenu(); 
            System.out.println("\f");
            switch(choice)
            {
                case 1 :  startAddressBook();       break;   // start AddressBook
                case 2 :  startDvd();               break;   // start DVD
                case 3 :  startLoan();              break;   // start Loan
                default : {writeEnd();exit=true; }  break;   // exit
            }
        }
    }

    private int writeMainMenu()
    {       
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** MainMenu ***");
        System.out.println(" (1) AddressBook");
        System.out.println(" (2) DVDs");
        System.out.println(" (3) Loan");
        System.out.println(" (4) Close");
        System.out.print("\n Make your choice: ");

        int choice = readInt();
        System.out.println("\f");

        return choice;
    }

    private void startAddressBook() {  adrUI= new AddressBookUI(); adrUI.start();  }
    private void startDvd()         {  dvdUI  = new DvdUI();       dvdUI.start();  }
    private void startLoan()        {  loanUI = new LoanUI();      loanUI.start(); }
    

    private void writeEnd()
    {
        System.out.println(" The System is shuting down ");
    }
}
